/*
 * 1.7
 * Write an algorithm such that if an element in an MxN matrix is 0, its entire row and
 * column is set to 0.
 */
#include <stdio.h>

template <int m, int n>
void print_matrix(int (&matrix)[m][n])
{
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            printf("%d ", matrix[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    const int m = 4, n = 3;
    int matrix[m][n] = { { 1, 2, 3 }, { 4, 5, 0 }, { 7, 8, 9 }, { 0, 11, 12 } };
    char row[m] = { 0 };
    char col[n] = { 0 };
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (matrix[i][j] == 0) {
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (row[i] || col[j]) {
                matrix[i][j] = 0;
            }
        }
    }
    print_matrix(matrix);
    return 0;
}
